package com.etc.service.impl;

import com.etc.dao.UserInfoDao;
import com.etc.dao.impl.UserInfoDaoImpl;
import com.etc.entity.UserInfo;
import com.etc.service.UserInfoService;
/**
 * 用户表Service实现类
 * @author nianxulin
 */
public class UserInfoServiceImpl implements UserInfoService{
	private UserInfoDao userInfoDao = new UserInfoDaoImpl();
	@Override
	public String adduser(String userName, String password, String mobile) {
		//中间变量判定循环
		int i= 1;
		String qq = null;
		//获取不重复qq号
		while (i!= 0) {
			qq = qq();
			i = userInfoDao.findQQ(qq); 
		}
		int adduser = userInfoDao.adduser(userName, password, qq, mobile);
		if (adduser>0) {
			return qq;
		}
		return null;
	}
	//获取10-11位qq号
	public String qq() {
		int ran1 = (int) (Math.random()*(99999-10000)+10000);
		int ran2 = (int) (Math.random()*(999999-10000)+10000);
		String qq = ""+ran1 + ran2;
		return qq;
	}
	@Override
	public int findMobile(String mobile) {
		
		return userInfoDao.findMobile(mobile);
	}
	@Override
	public UserInfo login(String accountNumber, String password) {
		return userInfoDao.login(accountNumber, password);
	}
}

	
